#ifndef THREECARDRUMMYGAME_H
#define THREECARDRUMMYGAME_H

#include "TGame.h"

class ThreeCardConnection;
class ThreeCardRummyHand;
class ThreeCardSavedGame;

//*************************************************************************************************
//
//  This class implements the game specific logic for Vegas Three Card Rummy.
//
//  Every hand of Rummy results in a new instance of this object being created.  When
//  that hand is completed, that object is destroyed.
//
//  kharmon.  01-31-06.  #5862.
//
//*************************************************************************************************

class ThreeCardRummyGame : public TGame
{
public:
    // used when starting a new game from scratch
    ThreeCardRummyGame(ThreeCardConnection*, int32 anteBet, int32 nSideBet);

    // used when restoring an unfinished game
    ThreeCardRummyGame(ThreeCardConnection*, ThreeCardSavedGame*);

    ~ThreeCardRummyGame();

    bool8 deal(int32 balance);      // called when the user hits the "deal" button.
    bool8 raise();                  // called when the user hits the "raise" button.
    bool8 fold();                   // called when the user hits the "fold" button.

    int32 getAnteBet();             // returns the amount of the user's initial bet
    int32 getSideBet();             // returns the amount of the user's "bonus" bet.  May be zero.

    void send();                    // sends this object's reponse back to the client.

    void save(ThreeCardSavedGame*); // doesn't actually do anything...

    bool8 isGameOK();               // called to make sure that the current game is valid, especially when restoring an existing game.

    ThreeCardRummyHand* getDealer()  { return m_pDealer; }
    ThreeCardRummyHand* getPlayer()  { return m_pPlayer; }


    enum AnteBonusPayTableTypes
    {
        AB_PAYFREQ_LOW,
        MAX_AB_PAYFREQ
    };

    enum SideBetPayTableTypes
    {
        SB_PAYFREQ_LOW,
        MAX_SB_PAYFREQ
    };

    // kharmon.  10-17-06.  #8226.
    // returns the deck seed that can be used to generate the cards for the current game.
    int32 getDeckSeed() { return m_nDeckSeed; }

protected:

    // does the "Game Done" processing for both "Raise" and "Fold" conditions.
    bool8 finish(char);

    // compares the dealer and player hands to see who won, and how much was won or lost by the player.
    bool8 calcPayouts(int32*, char, int32*, int32*);

    // called to restore an existing game so that the player can finish it.
    bool8 restore(ThreeCardSavedGame*);

protected:
    ThreeCardConnection*        m_pConn;                // object representing the connection back to the player, and to the database.
    int32                       m_nAnteBet, m_nSideBet; // the player's initial and bonus bet amounts.
    ThreeCardRummyHand*         m_pDealer;              // dealer's cards
    ThreeCardRummyHand*         m_pPlayer;              // player's cards.
    uint8                       m_nRaisePayTable;       // What payout values should be used when the player has the better hand and the dealer qualifies.
    uint8                       m_nSideBetPayTable;     // What payout values should be used when the player wins the "bonus bet".
    bool8                       m_bGameOK;

    int32                       m_nDeckSeed;            // kharmon.  10-17-06.  #8226. 


    //
    // *IMPORTANT*  When adding/changing here, be sure to update
    //                constructors/destructor, send(), save(), restore()
    //
};

inline int32
ThreeCardRummyGame::getAnteBet()
{
    return m_nAnteBet;
}

inline int32
ThreeCardRummyGame::getSideBet()
{
    return m_nSideBet;
}

inline bool8
ThreeCardRummyGame::isGameOK()
{
    return m_bGameOK;
}

#endif
